package com.cnhis.cloudhealth.clinical.clidoctor.patientcase.bo;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cnhis.cloudhealth.clinical.clidoctor.cliparamter.dao.CliParamterDao;
import com.cnhis.cloudhealth.clinical.clidoctor.patientcase.dao.PatientCaseDao;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.newid.GetNewId;
import com.cnhis.cloudhealth.commons.utils.DateUtils;
import com.cnhis.cloudhealth.commons.utils.JsonUtil;
import java.util.HashMap;
import com.cnhis.cloudhealth.commons.utils.Page;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;

import net.sf.json.JSONObject;

@SuppressWarnings("rawtypes")
@Service
public class PatientCaseBo
{
    @Resource
    private PatientCaseDao patientCaseDao;
    
    @Resource
    private CliParamterDao cliParamterDao;
    
    @Resource
    private GetNewId getNewId;
    
    public ModelVo patientCaseReminder(Map map, int currentPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            pg = patientCaseDao.patientCaseReminder(map, currentPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    public ModelVo patientCaseList(Map map, int currentPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            pg = patientCaseDao.patientCaseList(map, currentPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo patientEfficaciousCase(Map map, int currentPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            if ("0".equals(map.get("BCK01").toString()))
            {
                Map m = patientCaseDao.setparameters(map);
                map.put("BCK01", m.get("BCK01C").toString());
                map.put("DeptId", m.get("BCK01D").toString());
            }
            pg = patientCaseDao.patientEfficaciousCase(map, currentPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    public ModelVo viewInspectionReport(Map map, int currentPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            pg = patientCaseDao.viewInspectionReport(map, currentPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    public ModelVo findDefaultInstrumentEquipment()
        throws Exception
    {
        ModelVo modelVo = new ModelVo();
        List list = null;
        try
        {
            list = patientCaseDao.findDefaultInstrumentEquipment();
        }
        catch (Exception e)
        {
            modelVo.setResult(StaticKeys.OH_FALSE);
            return modelVo;
        }
        
        modelVo.setList(list);
        modelVo.setRows(list);
        modelVo.setResult(StaticKeys.OH_SUCCESS);
        return modelVo;
    }
    
    public ModelVo conventionResult(Map map, int currentPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            pg = patientCaseDao.conventionResult(map, currentPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    public ModelVo inspectionReportImage(Map map, int currentPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            pg = patientCaseDao.inspectionReportImage(map, currentPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    public ModelVo doctorConventionResult(Map map, int currentPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            pg = patientCaseDao.doctorConventionResult(map, currentPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    @SuppressWarnings({"unchecked", "rawtypes"})
    public ModelVo doctorViewImageResult(Map map, int currentPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            HashMap hashMap = new HashMap();
            hashMap.put("BLP02", 58);
            List list = patientCaseDao.restrictedCondition(hashMap);
            hashMap.put("productId", 300);
            hashMap.put("programId", 301004);
            hashMap.put("paramNo", 142);
            String value = cliParamterDao.getSysParamValue(hashMap);
            map.put("fuser", value);
            hashMap.put("productId", 300);
            hashMap.put("programId", 301004);
            hashMap.put("paramNo", 143);
            value = cliParamterDao.getSysParamValue(hashMap);
            map.put("fpass", value);
            hashMap.put("productId", 300);
            hashMap.put("programId", 301004);
            hashMap.put("paramNo", 140);
            value = cliParamterDao.getSysParamValue(hashMap);
            map.put("fhost", value);
            hashMap.put("productId", 300);
            hashMap.put("programId", 301004);
            hashMap.put("paramNo", 141);
            value = cliParamterDao.getSysParamValue(hashMap);
            map.put("fport", value);
            if (list != null && list.size() > 0)
            {
                pg = patientCaseDao.doctorViewImageReport(map, currentPage, pageSize);
            }
            else
            {
                pg = patientCaseDao.doctorViewImage(map, currentPage, pageSize);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo getLastHistory(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        List pg = null;
        Map hashMap = null;
        try
        {
            hashMap = patientCaseDao.queryParamter(map);
            map.put("mzBLP42", hashMap == null || hashMap.get("BLP04") == null ? 0 : hashMap.get("BLP04").toString());
            map.put("zyBLP42", hashMap == null || hashMap.get("BLP05") == null ? 0 : hashMap.get("BLP05").toString());
            if ("1".equals(map.get("aACF01").toString()))
            {
                
                pg = patientCaseDao.getLastHistory(map);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg);
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setRows(pg);
        return mo;
    }
    
    public ModelVo patientCaseHistory(Map map, int currentPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            pg = patientCaseDao.patientCaseHistory(map, currentPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    public ModelVo getPatinetCase(Map map)
        throws Exception
    {
        ModelVo modelVo = new ModelVo();
        List list = null;
        try
        {
            list = patientCaseDao.getPatinetCase(map);
        }
        catch (Exception e)
        {
            modelVo.setResult(StaticKeys.OH_FALSE);
            return modelVo;
        }
        
        modelVo.setList(list);
        modelVo.setRows(list);
        modelVo.setResult(StaticKeys.OH_SUCCESS);
        return modelVo;
    }
    
    public ModelVo fetchPatientSummary(Map map)
        throws Exception
    {
        ModelVo modelVo = new ModelVo();
        List list = null;
        try
        {
            list = patientCaseDao.fetchPatientSummary(map);
        }
        catch (Exception e)
        {
            modelVo.setResult(StaticKeys.OH_FALSE);
            return modelVo;
        }
        
        modelVo.setList(list);
        modelVo.setRows(list);
        modelVo.setResult(StaticKeys.OH_SUCCESS);
        return modelVo;
    }
    
    private boolean checkPatientCase(long vaq01)
        throws Exception
    {
        if (vaq01 > 0 && patientCaseDao.checkPatientCase(vaq01) == 0)
            return true;
        return false;
    }
    
    private boolean existsParam()
        throws Exception
    {
        return patientCaseDao.existsParam() > 0;
    }
    
    private Map getTmpVAQ(Map map)
        throws Exception
    {
        return patientCaseDao.getTmpVAQ(map);
    }
    
    private Map getParams(Map map)
        throws Exception
    {
        return patientCaseDao.getParams(map);
    }
    
    private Map getOffice(Map map)
        throws Exception
    {
        return patientCaseDao.getOffice(map);
    }
    
    private Integer getROWNR(Map map)
        throws Exception
    {
        return patientCaseDao.getROWNR(map);
    }
    
    @SuppressWarnings("unchecked")
    private void insertVAQ(Map map)
        throws Exception
    {
        map.put("newID", getNewId.nextId());
        patientCaseDao.insertVAQ(map);
    }
    
    private boolean existsCAF(Map map)
        throws Exception
    {
        return patientCaseDao.existsCAF(map) > 0;
    }
    
    private boolean existsCAF1(Map map)
        throws Exception
    {
        return patientCaseDao.existsCAF1(map) > 0;
    }
    
    private boolean existsCAF2(Map map)
        throws Exception
    {
        return patientCaseDao.existsCAF2(map) > 0;
    }
    
    private boolean existsCAF3(Map map)
        throws Exception
    {
        return patientCaseDao.existsCAF3(map) > 0;
    }
    
    private boolean existsCAF4(Map map)
        throws Exception
    {
        return patientCaseDao.existsCAF4(map) > 0;
    }
    
    private int getCAF05(Map map)
        throws Exception
    {
        return patientCaseDao.getCAF05(map);
    }
    
    private String getVAQ32(Map map)
        throws Exception
    {
        return patientCaseDao.getVAQ32(map);
    }
    
    private int getCAF1(Map map)
        throws Exception
    {
        return patientCaseDao.getCAF1(map);
    }
    
    private String getVAQ1(Map map)
        throws Exception
    {
        return patientCaseDao.getVAQ1(map);
    }
    
    private int getCAF2(Map map)
        throws Exception
    {
        return patientCaseDao.getCAF2(map);
    }
    
    private int getCAF3(Map map)
        throws Exception
    {
        return patientCaseDao.getCAF3(map);
    }
    
    private int getCAF4(Map map)
        throws Exception
    {
        return patientCaseDao.getCAF4(map);
    }
    
    private String getVAQ2(Map map)
        throws Exception
    {
        return patientCaseDao.getVAQ2(map);
    }
    
    @SuppressWarnings("unchecked")
    private String getVaq(Map map, Map tmpVAQ)
        throws Exception
    {
        int CAF05 = 0;
        if (tmpVAQ.get("CAD15") != null && !"".equals(tmpVAQ.get("CAD15")))
        {
            CAF05 = Integer.parseInt(tmpVAQ.get("CAD15").toString());
        }
        String VAQ32 = "9999-12-01";// 书写时限
        if (existsCAF(map))
        {
            CAF05 = getCAF05(map);
            map.put("CAF05", "CAF05");
            VAQ32 = getVAQ32(map);
        }
        else if (existsCAF1(map))
        {
            CAF05 = getCAF1(map);
            map.put("CAF05", "CAF05");
            VAQ32 = getVAQ1(map);
        }
        else if (existsCAF2(map))
        {
            CAF05 = getCAF2(map);
            map.put("CAF05", "CAF05");
            VAQ32 = getVAQ2(map);
        }
        else if (existsCAF3(map))
        {
            CAF05 = getCAF3(map);
            map.put("CAF05", "CAF05");
            VAQ32 = getVAQ2(map);
        }
        else if (existsCAF4(map))
        {
            CAF05 = getCAF4(map);
            map.put("CAF05", "CAF05");
            VAQ32 = getVAQ2(map);
        }
        return VAQ32;
    }
    
    @SuppressWarnings("unchecked")
    private void saveVAQ(Map map)
        throws Exception
    {
        map.put("newID", getNewId.nextId());
        patientCaseDao.saveVAQ(map);
    }
    
    private void saveVAR(Map map)
        throws Exception
    {
        patientCaseDao.saveVAR(map);
    }
    
    @SuppressWarnings("unchecked")
    private void saveVCC1(Map map)
        throws Exception
    {
        map.put("newID", getNewId.nextId());
        patientCaseDao.saveVCC1(map);
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo execEmrVAQ1Update(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        String state = map.get("State").toString();
        // 判断病历文件是否存在
        long VAQ01 = Long.parseLong(map.get("VAQ01").toString());
        if (checkPatientCase(VAQ01))
        {
            mo.setResult(StaticKeys.OH_FALSE);
            mo.setResultMsg("提交错误，病人病历信息为空");
            return mo;
        }
        String xml = map.get("XML").toString();
        JSONObject object = JSONObject.fromObject(xml);
        Map tmpVAQ = JsonUtil.parserToMap(object.getJSONObject("VAQ"));
        map.put("tmpVAQ", tmpVAQ);
        // 病历临时数据
        tmpVAQ = getTmpVAQ(map);
        if (("0".equals(state) || "2".equals(state)) && existsParam())
        {
            // 修改病历状态
            if (tmpVAQ.get("VAQ20") == null)
            {
                tmpVAQ.put("VAQ20", 1);
            }
            
        }
        int CAD15 = 0;// 保存文本附件，用于供病案或医保调用
        int CAD11 = 0;// 书写模式 0:单一病历 1:病历片段(例：病程记录;护里记录) 2:多人书写病历
        int CAB01;// 病历文件类型
        // long CAD01=Long.parseLong(tmpVAQ.get("CAD01").toString());//病历文件ID
        String CAD04;// 病历文件名称
        int ROWNR;
        // int ACF01=Integer.parseInt(tmpVAQ.get("ACF01").toString());
        
        if ("0".equals(state) || "1".equals(state))
        {
            // 新增病历记录
            map.put("CAD11", CAD11);
            Map m = getParams(map);
            CAB01 = Integer.parseInt(m.get("cab01").toString());
            CAD04 = m.get("cad04").toString();
            CAD11 = Integer.parseInt(m.get("cad11").toString());
            // 获取床位 科室
            m = getOffice(map);
            if (m != null)
            {
                tmpVAQ.put("BCK01B", m.get("bck01b") == null ? "" : m.get("bck01b"));
                tmpVAQ.put("BCQ04B", m.get("bcq04b") == null ? "" : m.get("bcq04b"));
                tmpVAQ.put("VAQ26", m.get("bcq04b") == null ? "" : m.get("bcq04b"));
                
            }
            // 更新临时数据
            // String VAE22 = m.get("vae22").toString();
            tmpVAQ.put("CAB01", CAB01);
            tmpVAQ.put("CAD11", CAD11);
            if (map.get("CAD04") == null || "".equals(map.get("CAD04").toString()))
            {
                tmpVAQ.put("CAD04", CAD04);
                
            }
            tmpVAQ.put("VAQ13", DateUtils.getDateString(new Date()));
            if (map.get("VAQ20") == null)
            {
                tmpVAQ.put("VAQ20", 0);
            }
            tmpVAQ.put("VAQ16", DateUtils.getDateString(new Date()));
            tmpVAQ.put("ROWNR", 1);
            // 判断是否连续病历，增加合并病历记录
            if ("1".equals(state))
            {
                if (VAQ01 > 0)
                {
                    ROWNR = getROWNR(map);
                }
                else
                {
                    ROWNR = 0;
                    // 增加记录
                    tmpVAQ.put("ROWNR", ROWNR);
                    map.put("tmpVAQ", tmpVAQ);
                    insertVAQ(map);
                }
            }
            else
            {
                if (VAQ01 > 0)
                {
                    ROWNR = getROWNR(map);
                }
                else
                {
                    ROWNR = 0;
                }
            }
            // 获取书写时限
            String VAQ32 = getVaq(map, tmpVAQ);
            map.put("VAQ32", VAQ32);
            map.put("ROWNR", ROWNR);
            // 初始化病人病历记录
            saveVAQ(map);
            // 初始化病人病历内容记录
            if (CAD15 == 1)
            {
                saveVAR(map);
            }
            // 病历内容修改记录日志
            map.put("State", 0);
            saveVCC1(map);
        }
        // 修改记录
        if ("2".equals(state))
        {
            // 修改病历记录
            updateVAQ1State2(map);
            // 病历内容修改记录日志
            map.put("State", 1);
            saveVCC1(map);
            if (CAD15 == 1)
            {
                // 修改病人病例内容
                updateVAR1(map);
            }
        }
        // 审阅
        if ("3".equals(state))
        {
            if ("1".equals(tmpVAQ.get("vbt10")))
            {
                // 修改病历历史状态为已阅
                updateVBT1(map);
            }
            // 修改病历保存人及签名、时间
            updateVaqState3(map);
            // 病历内容修改记录日志
            map.put("State", 2);
            saveVCC1(map);
        }
        // 归档
        if ("4".equals(state))
        {
            // 记录归档人和归档时间
            updateVAQState4(map);
            // 病历内容修改记录日志
            map.put("State", 3);
            saveVCC1(map);
            
        }
        // 取消归档
        if ("5".equals(state))
        {
            String BCE01C = tmpVAQ.get("BCE01C").toString();
            HashMap hs = new HashMap();
            hs.put("BCE01C", BCE01C);
            if (empPermissionValue(hs))
            {
                mo.setResult(StaticKeys.OH_FALSE);
                mo.setResultMsg("你没有权限取消归档");
                return mo;
            }
            // 取消归档
            updateVAQState5(map);
            // 病历内容修改记录日志
            map.put("State", 5);
            saveVCC1(map);
        }
        // 评分
        if ("6".equals(state))
        {
            
            updateVAQState6(map);
            // 病历内容修改记录日志
            map.put("State", 6);
            saveVCC1(map);
        }
        // 取消评分
        if ("7".equals(state))
        {
            // 取消评分
            updateVAQState7(map);
            // 病历内容修改记录日志
            map.put("State", 7);
            saveVCC1(map);
        }
        return mo;
    }
    
    private void updateVAQ1State2(Map map)
        throws Exception
    {
        patientCaseDao.updateVAQ1(map);
    }
    
    private void updateVAR1(Map map)
        throws Exception
    {
        patientCaseDao.updateVAR1(map);
    }
    
    private void updateVBT1(Map map)
        throws Exception
    {
        patientCaseDao.updateVBT1(map);
    }
    
    private void updateVaqState3(Map map)
        throws Exception
    {
        patientCaseDao.updateVaq1(map);
    }
    
    private void updateVAQState4(Map map)
        throws Exception
    {
        patientCaseDao.updateVAQState4(map);
    }
    
    private boolean empPermissionValue(Map map)
        throws Exception
    {
        return patientCaseDao.empPermissionValue(map) == 0;
    }
    
    private void updateVAQState5(Map map)
        throws Exception
    {
        patientCaseDao.updateVAQState5(map);
    }
    
    private void updateVAQState6(Map map)
        throws Exception
    {
        patientCaseDao.updateVAQState6(map);
    }
    
    private void updateVAQState7(Map map)
        throws Exception
    {
        patientCaseDao.updateVAQState7(map);
    }
    
    public ModelVo findHistory(Map map, int currPage, int pageSize)
        throws Exception
    {
        ModelVo mo = new ModelVo();
        Page pg = null;
        try
        {
            pg = patientCaseDao.findHistory(map, currPage, pageSize);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            mo.setResult(StaticKeys.OH_FALSE);
            return mo;
        }
        
        mo.setList(pg.getList());
        mo.setResult(StaticKeys.OH_SUCCESS);
        mo.setTotal(pg.getTotalNumber());
        mo.setRows(pg.getList());
        return mo;
    }
    
    private void updateVAQ32(Map map)
        throws Exception
    {
        patientCaseDao.updateVAQ32(map);
    }
    
    @SuppressWarnings("unchecked")
    private void insertVCC1(Map map)
        throws Exception
    {
        map.put("newID", getNewId.nextId());
        patientCaseDao.insertVCC1(map);
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo execEmrVaq1Vaq32Update(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        String xml = map.get("xml").toString();
        JSONObject json = JSONObject.fromObject(xml);
        Map OperInfo = JsonUtil.parserToMap(json.getJSONObject("OperInfo"));
        Map VAQ1 = JsonUtil.parserToMap(json.getJSONObject("VAQ1"));
        // 修改时限
        updateVAQ32(VAQ1);
        // 增加日志
        OperInfo.put("VAQ01", VAQ1.get("VAQ01").toString());
        insertVCC1(OperInfo);
        return mo;
    }
    
    private void insertVCU1(Map map)
        throws Exception
    {
        patientCaseDao.insertVCU1(map);
    }
    
    private void updateVAQ1Title(Map map)
        throws Exception
    {
        patientCaseDao.updateVAQ1Title(map);
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo execEmrVcu1Update(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        String xml = map.get("XML").toString();
        JSONObject jsonObject = JSONObject.fromObject(xml);
        List vcu1List = JsonUtil.getList(jsonObject.getJSONArray("VCU1").toString());
        map.put("vcu1List", vcu1List);
        // 新增病历新增标记信息
        insertVCU1(map);
        // 修改病历名称
        updateVAQ1Title(map);
        return mo;
    }
    
    private Map params(Map map)
        throws Exception
    {
        return patientCaseDao.params(map);
    }
    
    @SuppressWarnings("unchecked")
    private void insertQAD1(Map map)
        throws Exception
    {
        map.put("newID", getNewId.nextId());
        patientCaseDao.insertQAD1(map);
    }
    
    @SuppressWarnings("unchecked")
    private void updateQAD1(Map map)
        throws Exception
    {
        map.put("newID", getNewId.nextId());
        patientCaseDao.updateQAD1(map);
    }
    
    @SuppressWarnings("unchecked")
    public ModelVo execQcQad1init(Map map)
        throws Exception
    {
        ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
        // 获取参数
        Map params = params(map);
        String qad01 = "0";
        String qad13 = "0";
        if (params != null)
        {
            qad01 = params.get("qad01").toString();
            qad13 = params.get("qad13").toString();
            
        }
        map.put("params", params);
        if ("0".equals(qad01))
        {// 判断是否有记录没有则新增
            insertQAD1(map);
        }
        else if ("4".equals(qad13))
        {
            updateQAD1(map);
        }
        
        return mo;
    }
}
